/**
 *
 * @package    mahara
 * @subpackage artefact-feedback
 * @author     laurent.opprecht@gmail.com
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2011 University of Geneva http://www.unige.ch/
 *
 */

(function(){

    /**
     * Dynamically attach the default CSS style for feedbacks.
     * Needed to attach it to Views which does not allow for addition of new CSS.
     * Will only work for the RAW theme.
     */
    function loadCss() {
        var href = config['wwwroot'] + 'artefact/feedback/theme/raw/static/style/style.css';
        var scripts = document.getElementsByTagName('link');

        for(var i= 0; i < scripts.length; i++)
        {
            if(scripts[i].getAttribute('href') == href){
                return;
            }
        }

        var head= document.getElementsByTagName('head')[0];
        var link= document.createElement('link');
        link.type= 'text/css';
        link.rel = 'stylesheet';
        link.href= href;
        head.appendChild(link);
    }

    function get_url_parameter(name){
        var u = document.location.href;
        var reg = new RegExp('(\\?|&|^)'+name+'=(.*?)(&|$)');
        matches = u.match(reg);
        return matches[2] != undefined ? decodeURIComponent(matches[2]).replace(/\+/g,' ') : '';
    }

    loadCss();

})();

/**
 * Called after "add_parentfeedback" form submit event is processed.
 * Reset the form and update the table
 */
function addParentFeedbackSuccess(form, data) {
    form.message.value = '';
    form.ispublic.checked = true;
    
    toggleElementClass('collapsed', 'add_form');
    if(data.data){
        paginator.updateResults(data);
    }

    if(data.goto){
        window.location.href = data.goto;
        return;
    }

}
